package com.css.fxfzaqbz.modules.data.repository.impl;


import com.css.fxfzaqbz.constants.YNEnum;
import com.css.fxfzaqbz.modules.data.entity.ImportantActivity;
import com.css.fxfzaqbz.modules.data.entity.Region;
import com.css.fxfzaqbz.modules.data.entity.Site;
import com.css.fxfzaqbz.modules.data.queryParams.ImportantActivityQueryParams;
import com.css.fxfzaqbz.modules.data.repository.ImportantActivityRepository;
import com.css.fxfzaqbz.util.PlatformObjectUtils;
import com.css.fxfzaqbz.util.PlatformSessionUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Repository
public class ImportantActivityRepositoryImpl implements ImportantActivityRepository {

    @Resource
    JdbcTemplate jdbcTemplate;
    @Resource
    NamedParameterJdbcTemplate namedParameterJdbcTemplate;


    @Override
    @Transactional
    public ImportantActivity saveImportantActivity(ImportantActivity importantActivity) {
        String sql = "insert into sys_important_activity (" +
                "ia_id,ia_number,ia_name,ia_province,ia_city,ia_counties," +
                "ia_code,ia_starting_time,ia_zddw_ywrys,ia_ssdw_ywrys,ia_xtdw_ywrys," +
                "ia_finsh_time,ia_zdmb,ia_wjtz,ia_hdjj,ia_zddw,ia_zddw_ywry,ia_ssdw,ia_ssdw_ywry,ia_xtdw," +
                "ia_xtdw_ywry,ia_cbsh,ia_bmsh,ia_ldsh,cbsh_id,bmsh_id,ldsh_id,ia_cjr,ia_cjr_dw,ia_lxfs,ia_email,del_flag," +
                "create_time,update_time,ia_activity_status,province_id,city_id,counties_id,create_user,create_time2,ia_zddw_ywry_fg,ia_ssdw_ywry_fg,ia_xtdw_ywry_fg,ia_opinion,ia_opinion_status," +
                "jcz_dw,jcz_zz,jcz_cy,jcz_zyzz,jcz_gzcs,fxz_dw,fxz_zz,fxz_cy,fxz_zyzz,fxz_gzcs," +
                "yjz_dw,yjz_zz,yjz_cy,yjz_zyzz,yjz_gzcs,xwz_dw,xwz_zz,xwz_cy,xwz_zyzz,xwz_gzcs," +
                "zsz_dw,zsz_zz,zsz_cy,zsz_zyzz,zsz_gzcs,hdlb" +
                ")values(" +
                ":iaId,:iaNumber,:iaName,:iaProvince," +
                ":iaCity,:iaCounties,:iaCode,:iaStartingTime,:iaZddwYwrys,:iaSsdwYwrys,:iaXtdwYwrys," +
                ":iaFinshTime,:iaZdmb,:iaWjtz,:iaHdjj,:iaZddw," +
                ":iaZddwYwry,:iaSsdw,:iaSsdwYwry,:iaXtdw,:iaXtdwYwry," +
                ":iaCbsh,:iaBmsh,:iaLdsh,:cbshId,:bmshId,:ldshId,:iaCjr,:iaCjrDw,:iaLxfs,:iaEmail," +
                ":delFlag,:createTime,:updateTime,:iaActivityStatus,:provinceId,:cityId,:countiesId,:createUser,:createTime2,:iaZddwYwryFg,:iaSsdwYwryFg,:iaXtdwYwryFg,:iaOpinion,:iaOpinionStatus," +
                ":jczDw,:jczZz,:jczCy,:jczZyzz,:jczGzcs,:fxzDw,:fxzZz,:fxzCy,:fxzZyzz,:fxzGzcs," +
                ":yjzDw,:yjzZz,:yjzCy,:yjzZyzz,:yjzGzcs,:xwzDw,:xwzZz,:xwzCy,:xwzZyzz,:xwzGzcs," +
                ":zszDw,:zszZz,:zszCy,:zszZyzz,:zszGzcs,:hdlb)";

        SqlParameterSource source = new BeanPropertySqlParameterSource(importantActivity);
        //拿到新插入的主键值（i）
        KeyHolder keyHolder = new GeneratedKeyHolder();
        int i = namedParameterJdbcTemplate.update(sql, source, keyHolder);
        return importantActivity;
    }

    @Override
    public Map<String, Object> getAllImportantActivityParams(ImportantActivityQueryParams queryParams) {
        StringBuilder sql = new StringBuilder(" select  i.* from sys_important_activity i ");

        StringBuilder orderSql = new StringBuilder(" order by i.create_time desc");

        StringBuilder whereSql = new StringBuilder(" where i.del_flag = '" + YNEnum.N.toString() + "' and i.ia_activity_status ='" + YNEnum.Y + "' and i.create_user != '"+ PlatformSessionUtils.getUserId()+"'");

//        if (!PlatformObjectUtils.isEmpty(queryParams.getProvinceId()) && queryParams.getProvinceId() != "") {
//            whereSql.append(" and i.province_id ='" + queryParams.getProvinceId() + "'");
//        }
//        if (!PlatformObjectUtils.isEmpty(queryParams.getDlrId())) {
//            whereSql.append(" and i.create_user  ='" + queryParams.getDlrId() + "'");
//        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaProvince())) {
            whereSql.append(" and i.ia_province  ='" + queryParams.getIaProvince() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaCity())) {
            whereSql.append(" and i.ia_city  ='" + queryParams.getIaCity() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaCounties())) {
            whereSql.append(" and i.ia_counties  ='" + queryParams.getIaCounties() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getCreateTime2())) {
            whereSql.append(" and i.create_time2 >='" + queryParams.getCreateTime2() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaFinshTime())) {
            whereSql.append(" and i.ia_finsh_time <='" + queryParams.getIaFinshTime() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaNumber())) {
            whereSql.append(" and i.ia_number like'%" + queryParams.getIaNumber() + "%'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaActivityStatus())) {
            whereSql.append(" and i.ia_activity_status ='" + queryParams.getIaActivityStatus() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaCjr())) {
            whereSql.append(" and i.ia_cjr like'%" + queryParams.getIaCjr() + "%'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaName())) {
            whereSql.append(" and i.ia_name like'%" + queryParams.getIaName() + "%'");
        }
//        int firstIndex = (queryParams.getCurPage() - 1) * queryParams.getPageSize();
//        //int lastIndex=queryParams.getCurPage() * queryParams.getPageSize();
//        int lastIndex = queryParams.getPageSize();
//        sql.append(whereSql).append(orderSql).toString();
//        StringBuilder limitSql = new StringBuilder(" limit " + lastIndex + " offset " + firstIndex);

        sql.append(whereSql).append(orderSql).toString();
        System.out.println(sql);
        Integer total = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(ImportantActivity.class)).size();
        List<ImportantActivity> importantActivities = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(ImportantActivity.class));
        Map<String, Object> map = new HashMap();
        map.put("total", total);
        map.put("rows", importantActivities);
        return map;
    }

    @Override
    public ImportantActivity getImportantActivityById(String id) {
        String sql = "select * from sys_important_activity where ia_id = '" + id + "'  and del_flag = '" + YNEnum.N + "'";
        ImportantActivity importantActivity = null;
        try {
            importantActivity = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(ImportantActivity.class));
        } catch (DataAccessException e) {
            return null;
        }
        return importantActivity;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteImportantActivitysById(List<String> ids, Timestamp timestamp, String userId) {
        String sql = "update sys_important_activity set del_flag = '" + YNEnum.Y + "' , update_time = '" + timestamp + "' ,update_user = '" + userId + "'" + " where ia_id in (:ids)";
        Map map = new HashMap();
        map.put("ids", ids);
        namedParameterJdbcTemplate.update(sql, map);
    }

    @Override
    public List<ImportantActivity> searchList(ImportantActivityQueryParams queryParams) {
        StringBuilder sql = new StringBuilder(" select  i.* from sys_important_activity i ");

        StringBuilder orderSql = new StringBuilder(" order by i.ia_number");

        StringBuilder whereSql = new StringBuilder(" where i.del_flag = '" + YNEnum.N.toString() + "'");

        if (!PlatformObjectUtils.isEmpty(queryParams.getIaName())) {
            whereSql.append(" and i.ia_name like '%" + queryParams.getIaName() + "%'");
        }

        sql.append(whereSql).append(orderSql).toString();
        List<ImportantActivity> importantActivities = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(ImportantActivity.class));
        return importantActivities;
    }

    @Override
    public ImportantActivity updateOpinionStatus(ImportantActivity importantActivity) {
        String sql = "update sys_important_activity set ia_opinion_status = '" + YNEnum.Y + "' where ia_id  = '" + importantActivity.getIaId() + "'";
        SqlParameterSource source = new BeanPropertySqlParameterSource(importantActivity);
        //拿到新插入的主键值（i）
        KeyHolder keyHolder = new GeneratedKeyHolder();
        namedParameterJdbcTemplate.update(sql, source, keyHolder);
        return importantActivity;
    }

    @Override
    public void timedUpdateOpinionStatus() {
        String sql = "update sys_important_activity set ia_opinion_status = '" + YNEnum.N + "' ";
        jdbcTemplate.update(sql);
    }

    @Override
    public String getNewIAId(Timestamp startTimestamp, Timestamp endTimestamp) {

        try {
            String sql = "select count(ia_number) as ia_number from sys_important_activity where create_time between '" + startTimestamp + "' and '" + endTimestamp + "'";
            return jdbcTemplate.queryForObject(sql, String.class);
        } catch (DataAccessException e) {
            return "0";
        }

    }

    @Override
    public List<ImportantActivity> getAllActivity(String provinceId) {
        StringBuilder sql = new StringBuilder(" select  i.* from sys_important_activity i ");

        StringBuilder orderSql = new StringBuilder(" order by i.create_time desc");

        StringBuilder whereSql = new StringBuilder(" where i.del_flag = '" + YNEnum.N.toString() + "'");

        if (!PlatformObjectUtils.isEmpty(provinceId) && provinceId != "") {
            whereSql.append(" and i.province_id ='" + provinceId + "'");
        }

        List<ImportantActivity> importantActivities = jdbcTemplate.query(sql.append(whereSql).append(orderSql).toString(), new BeanPropertyRowMapper<>(ImportantActivity.class));
        return importantActivities;
    }

    @Override
    public void updateActivityEndStatus(Timestamp timestamp, String iaId) {
        String sql = "update sys_important_activity set ia_activity_status = '" + YNEnum.Y + "' ,update_time ='"+timestamp+"' where ia_id  = '" + iaId+ "'";
        jdbcTemplate.update(sql);
    }

    @Override
    public Map<String, Object> getAll(ImportantActivityQueryParams queryParams) {
        StringBuilder sql = new StringBuilder(" select  i.* from sys_important_activity i ");

        StringBuilder orderSql = new StringBuilder(" order by i.create_time desc");

        StringBuilder whereSql = new StringBuilder(" where i.del_flag = '" + YNEnum.N.toString() + "' and i.create_user ='"+ PlatformSessionUtils.getUserId()+"'");

//        if (!PlatformObjectUtils.isEmpty(queryParams.getProvinceId()) && queryParams.getProvinceId() != "") {
//            whereSql.append(" and i.province_id ='" + queryParams.getProvinceId() + "'");
//        }
//        if (!PlatformObjectUtils.isEmpty(queryParams.getDlrId())) {
//            whereSql.append(" and i.create_user  ='" + queryParams.getDlrId() + "'");
//        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaProvince())) {
            whereSql.append(" and i.ia_province  ='" + queryParams.getIaProvince() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaCity())) {
            whereSql.append(" and i.ia_city  ='" + queryParams.getIaCity() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaCounties())) {
            whereSql.append(" and i.ia_counties  ='" + queryParams.getIaCounties() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getCreateTime2())) {
            whereSql.append(" and i.create_time2 >='" + queryParams.getCreateTime2() + "' ");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaFinshTime())) {
            whereSql.append(" and i.ia_finsh_time <='" + queryParams.getIaFinshTime() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaNumber())) {
            whereSql.append(" and i.ia_number ='" + queryParams.getIaNumber() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaActivityStatus())) {
            whereSql.append(" and i.ia_activity_status ='" + queryParams.getIaActivityStatus() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaCjr())) {
            whereSql.append(" and i.ia_cjr ='" + queryParams.getIaCjr() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaName())) {
            whereSql.append(" and i.ia_name like'%" + queryParams.getIaName() + "%'");
        }
//        int firstIndex = (queryParams.getCurPage() - 1) * queryParams.getPageSize();
//        //int lastIndex=queryParams.getCurPage() * queryParams.getPageSize();
//        int lastIndex = queryParams.getPageSize();
//        sql.append(whereSql).append(orderSql).toString();
//        StringBuilder limitSql = new StringBuilder(" limit " + lastIndex + " offset " + firstIndex);
        System.out.println(sql);
        sql.append(whereSql).append(orderSql).toString();
        Integer total = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(ImportantActivity.class)).size();
        List<ImportantActivity> importantActivities = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(ImportantActivity.class));
        Map<String, Object> map = new HashMap();
        map.put("total", total);
        map.put("rows", importantActivities);
        return map;
    }

    @Override
    public List<String> getAllSiteName(String province,String city,String counties) {

        try {
            String sql = "select ss_jzwmc  from sys_site where if_submit ='"+YNEnum.Y+"' and ss_province='"+province+"' and ss_city='"+city+"' and ss_counties='"+counties+"'";
            return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(String.class));
        } catch (DataAccessException e) {
            return null;
        }
    }

    @Override
    public List<String> getAllSiteName1(Region region) {
        try {
            StringBuilder sql = new StringBuilder("select distinct ss_jzwmc  from sys_site where if_submit ='" + YNEnum.Y + "' and ss_province='" + region.getProvince() + "'");
            if(PlatformObjectUtils.isNotEmpty(region.getCity())||region.getCity()!=null){
                sql.append(" and ss_city ='"+region.getCity()+"'");
            }
            if(PlatformObjectUtils.isNotEmpty(region.getCounty())||region.getCounty()!=null){
                sql.append(" and ss_counties ='"+region.getCounty()+"'");
            }
            List<Site> sites = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(Site.class));
            List<String> strings = sites.stream().map(Site::getSsJzwmc).collect(Collectors.toList());
            return strings;
        } catch (DataAccessException e) {
            return new ArrayList<>();
        }
    }

    @Override
    public String getCodeByIaId(String iaId) {
        try {
            String sql = "select ST_extent(st_geomfromtext(coordinate)) from district_boundary where code=(select ia_code from sys_important_activity where ia_id='"+iaId+"');";
            return jdbcTemplate.queryForObject(sql,String.class);
        } catch (DataAccessException e) {
            return null;
        }
    }

    @Override
    public Map<String, Object> getAllByRole(ImportantActivityQueryParams queryParams, String roleSql) {
        StringBuilder sql = new StringBuilder(" select * from sys_important_activity ");

        StringBuilder orderSql = new StringBuilder(" order by create_time desc");

        StringBuilder whereSql = new StringBuilder(" where del_flag = '" + YNEnum.N.toString() + "'");

        if (!PlatformObjectUtils.isEmpty(queryParams.getProvinceId())) {
            whereSql.append(" and province_id  ='" + queryParams.getProvinceId() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getCityId())) {
            whereSql.append(" and city_id  ='" + queryParams.getCityId() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getCountiesId())) {
            whereSql.append(" and counties_id  ='" + queryParams.getCountiesId() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getCreateTime2())) {
            whereSql.append(" and create_time2 >='" + queryParams.getCreateTime2() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaFinshTime())) {
            whereSql.append(" and ia_finsh_time <='" + queryParams.getIaFinshTime() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaNumber())) {
            whereSql.append(" and ia_number like '%" + queryParams.getIaNumber() + "%'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaActivityStatus())) {
            whereSql.append(" and ia_activity_status ='" + queryParams.getIaActivityStatus() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaCjr())) {
            whereSql.append(" and ia_cjr like '%" + queryParams.getIaCjr() + "%'");
        }
        if (!PlatformObjectUtils.isEmpty(queryParams.getIaName())) {
            whereSql.append(" and ia_name like '%" + queryParams.getIaName() + "%'");
        }
        if (!PlatformObjectUtils.isEmpty(roleSql)) {
            whereSql.append(roleSql);
        }
        int firstIndex=(queryParams.getCurPage()-1) * queryParams.getPageSize();
        int lastIndex=queryParams.getPageSize();
        StringBuilder limitSql = new StringBuilder(" limit "+lastIndex+" offset "+ firstIndex);
        sql.append(whereSql).append(orderSql).toString();
        Integer total = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(ImportantActivity.class)).size();
        sql.append(limitSql).toString();
        List<ImportantActivity> importantActivities = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(ImportantActivity.class));
        Map<String, Object> map = new HashMap();
        map.put("total", total);
        map.put("rows", importantActivities);
        return map;
    }
//    @Override
//    public List<ActiveFaultData> getAll() {
//        return jdbcTemplate.query("select * from sys_activefaultdata where afd_status = '"+YNEnum.Y+"'",new BeanPropertyRowMapper<>(ActiveFaultData.class));
//    }

//    @Override
//    public void importExcel(List<ActiveFaultData> activeFaultData) {
//        jdbcTemplate.batchUpdate("insert into sys_activefaultdata (afd_id,afd_number,afd_name,afd_length,afd_newactivity,afd_status,afd_createtime)values(?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() {
//            @Override
//            public int getBatchSize() {
//                return activeFaultData.size();
//            }
//            @Override
//            public void setValues(PreparedStatement ps, int i) throws SQLException {
//                ps.setString(1, activeFaultData.get(i).getAfdId());
//                ps.setString(2,activeFaultData.get(i).getAfdNumber());
//                ps.setString(3,activeFaultData.get(i).getAfdName());
//                ps.setString(4,activeFaultData.get(i).getAfdLength());
//                ps.setString(5,activeFaultData.get(i).getAfdNewactivity());
//                ps.setString(6,activeFaultData.get(i).getAfdStatus());
//                java.sql.Date createtime = new java.sql.Date(activeFaultData.get(i).getAfdCreatetime().getTime()) ;
//                ps.setDate(7,createtime);
//            }
//        });
//    }

    @Override
    public ImportantActivity updateImportantActivity(ImportantActivity importantActivity) {

        String sql = "update sys_important_activity set " +
                "ia_number = :iaNumber,ia_name=:iaName,ia_province=:iaProvince," +
                "ia_city=:iaCity,ia_counties=:iaCounties,ia_code=:iaCode," +
                "ia_starting_time=:iaStartingTime,ia_finsh_time=:iaFinshTime," +
                "ia_zdmb=:iaZdmb,ia_wjtz=:iaWjtz,ia_hdjj=:iaHdjj," +
                "ia_zddw = :iaZddw,ia_zddw_ywry=:iaZddwYwry,ia_ssdw=:iaSsdw," +
                "ia_ssdw_ywry=:iaSsdwYwry,ia_xtdw=:iaXtdw," +
                "ia_xtdw_ywry=:iaXtdwYwry,ia_cbsh=:iaCbsh,ia_bmsh=:iaBmsh," +
                "ia_ldsh=:iaLdsh,ia_cjr=:iaCjr,ia_cjr_dw=:iaCjrDw," +
                "ia_lxfs=:iaLxfs,ia_email=:iaEmail,province_id=:provinceId," +
                "city_id=:cityId,counties_id=:countiesId," +
                "update_user = :updateUser," +
                "cbsh_id = :cbshId,bmsh_id=:bmshId,ldsh_id=:ldshId," +
                "update_time = :updateTime," +
                "create_time2 = :createTime2," +
                "ia_opinion = :iaOpinion," +
                "ia_opinion_status = :iaOpinionStatus," +
                "ia_zddw_ywrys=:iaZddwYwrys," +
                "ia_ssdw_ywrys=:iaSsdwYwrys," +
                "ia_xtdw_ywrys=:iaXtdwYwrys," +
                "jcz_dw=:jczDw,jcz_zz=:jczZz,jcz_cy=:jczCy,jcz_zyzz=:jczZyzz,jcz_gzcs=:jczGzcs," +
                "fxz_dw=:fxzDw,fxz_zz=:fxzZz,fxz_cy=:fxzCy,fxz_zyzz=:fxzZyzz,fxz_gzcs=:fxzGzcs," +
                "yjz_dw=:yjzDw,yjz_zz=:yjzZz,yjz_cy=:yjzCy,yjz_zyzz=:yjzZyzz,yjz_gzcs=:yjzGzcs," +
                "xwz_dw=:xwzDw,xwz_zz=:xwzZz,xwz_cy=:xwzCy,xwz_zyzz=:xwzZyzz,xwz_gzcs=:xwzGzcs," +
                "zsz_dw=:zszDw,zsz_zz=:zszZz,zsz_cy=:zszCy,zsz_zyzz=:zszZyzz,zsz_gzcs=:zszGzcs,hdlb=:hdlb" +
                " where ia_id = '" + importantActivity.getIaId() + "'";

        SqlParameterSource source = new BeanPropertySqlParameterSource(importantActivity);
        //拿到新插入的主键值（i）
        KeyHolder keyHolder = new GeneratedKeyHolder();
        namedParameterJdbcTemplate.update(sql, source, keyHolder);
        return importantActivity;
    }

}
